﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JSTT_DATA_ENTITY.XMLDatas
{
    public class testXML
    {
        public static void TestGenerateXMLFile()
        {
            JSTT_DataRuleFormats drf = new JSTT_DataRuleFormats();
            drf.SetRuleFormatDescription("JSTT_RULE1","SocketData",1024,1024);

            drf.JSTT_RuleTableInfo.CurrencyTableName = "TF_JSTT_DATAS_CURRENCY_T01";
            drf.JSTT_RuleTableInfo.HistoryTableName= "TF_JSTT_DATAS_T01";
            drf.JSTT_RuleTableInfo.AddTableColumn("ID","","int",4,1,"true");
            drf.JSTT_RuleTableInfo.AddTableColumn("JST_DEVICE_ID", "DEVICE ID", "int", 4);
            drf.JSTT_EXPTDataItems.AddEXPTDataItem("X1","D1",0,1,1,1,"byte");
            drf.JSTT_EXPTDataItems.AddEXPTDataItem("X2","D2",0,1,1,1,"byte");
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_DEVICE_SIM", "DTU SIM号", "nvarchar", 20);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_DATA_SEND_TYPE", "数据发出类型", "smallint", 2);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_AFTERCONTROL_EXIST", "有无后续控制", "smallint", 2);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_DATA_EXCPT_TYPE", "数据类型", "smallint", 2);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_DATATYPE_ID", "设备类型", "int", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_DATA_DEV_ID", "设备ID", "int", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_DATE", "发送日期", "smalldatetime", 12);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_PT_VAL", "PT值", "int", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_A_VOL_VAL", "A相电压", "int", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_B_VOL_VAL", "B相电压", "int", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_C_VOL_VAL", "C相电压", "int", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_CT_VAL", "CT值", "int", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_A_ELEC_VAL", "A相电流", "int", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_B_ELEC_VAL", "B相电流", "int", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_C_ELEC_VAL", "C相电流", "int", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_N_ELEC_VAL", "N相电流", "int", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_A_POWER_FACTOR", "A相功率因数", "int", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_B_POWER_FACTOR", "B相功率因数", "int", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_C_POWER_FACTOR", "C相功率因数", "int", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_A_ACT_POWER", "A相有功功率", "int", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_B_ACT_POWER", "B相有功功率", "int", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_C_ACT_POWER", "C相有功功率", "int", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_A_REACT_POWER", "A相无功功率", "int", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_B_REACT_POWER", "B相无功功率", "int", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_C_REACT_POWER", "C相无功功率", "int", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_A_RATE", "A相频率", "int", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_B_RATE", "B相频率", "int", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_C_RATE", "C相频率", "int", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_A_ACT_ENERGY", "A相有功电量", "bigint", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_B_ACT_ENERGY", "B相有功电量", "bigint", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_C_ACT_ENERGY", "C相有功电量", "bigint", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_A_REACT_ENERGY", "A相无功电量", "bigint", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_B_REACT_ENERGY", "B相无功电量", "bigint", 4);
            //drf.JSTT_RuleTableInfo.AddTableColumn("JST_C_REACT_ENERGY", "C相无功电量", "bigint", 4);

            //drf.JSTT_RuleDataItems.AddDataRuleItem("起始位1","Number",0,0,1,0,"byte",true,"68H",false,"",1);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("客户DTUSIM号", "BCD8421", 1, 0, 6, 0, "byte", false, "", true, "JST_DEVICE_SIM", 2);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("起始位2","Number",7,0,1,0,"byte",true,"68H",false,"",3);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("数据发出类型", "BCD8421", 8, 0, 1, 1, "bit", false, "", true, "JST_DATA_SEND_TYPE", 4);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("有无后续控制", "Number", 8, 1, 1, 1, "bit", false, "", true, "JST_AFTERCONTROL_EXIST", 5);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("数据类型", "Number", 8, 2, 1, 5, "bit", false, "", true, "JST_DATA_EXCPT_TYPE", 6);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("数据长度", "Number", 9, 0, 2, 0, "btye", false, "", false, "", 7);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("设备类型", "Number", 11, 0, 1, 0, "byte", false, "", true, "JST_DATATYPE_ID", 8);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("设备ID", "Number", 12, 0, 6, 0, "byte", false, "", true, "JST_DATA_DEV_ID", 9);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("数据送出日期", "BCD8421", 18, 0, 4, 0, "byte", false, "", true, "JST_DATE", 10);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("PT值", "Number", 22, 0, 2, 0, "byte", false, "", true, "JST_PT_VAL", 11);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("A相电压", "Number", 24, 0, 2, 0, "byte", false, "", true, "JST_A_VOL_VAL", 12);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("B相电压", "Number", 26, 0, 2, 0, "byte", false, "", true, "JST_B_VOL_VAL", 13);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("C相电压", "Number", 28, 0, 2, 0, "byte", false, "", true, "JST_C_VOL_VAL", 14);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("CT值", "Number", 30, 0, 2, 0, "byte", false, "", true, "JST_CT_VAL", 15);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("A相电流", "Number", 32, 0, 2, 0, "byte", false, "", true, "JST_A_ELEC_VAL", 16);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("B相电流", "Number", 34, 0, 2, 0, "byte", false, "", true, "JST_B_ELEC_VAL", 17);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("C相电流", "Number", 36, 0, 2, 0, "byte", false, "", true, "JST_C_ELEC_VAL", 18);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("N相电流", "Number", 38, 0, 2, 0, "byte", false, "", true, "JST_C_ELEC_VAL", 19);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("A相功率因素", "Number", 40, 0, 1, 0, "byte", false, "", true, "JST_A_POWER_FACTOR", 20);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("B相功率因素", "Number", 41, 0, 1, 0, "byte", false, "", true, "JST_B_POWER_FACTOR", 21);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("C相功率因素", "Number", 42, 0, 1, 0, "byte", false, "", true, "JST_C_POWER_FACTOR", 22);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("A相有功功率", "Number", 43, 0, 2, 0, "byte", false, "", true, "JST_A_ACT_POWER", 23);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("B相有功功率", "Number", 45, 0, 2, 0, "byte", false, "", true, "JST_B_ACT_POWER", 24);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("C相有功功率", "Number", 47, 0, 2, 0, "byte", false, "", true, "JST_C_ACT_POWER", 25);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("A相无功功率", "Number", 49, 0, 2, 0, "byte", false, "", true, "JST_A_REACT_POWER", 26);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("B相无功功率", "Number", 51, 0, 2, 0, "byte", false, "", true, "JST_B_REACT_POWER", 27);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("C相无功功率", "Number", 53, 0, 2, 0, "byte", false, "", true, "JST_C_REACT_POWER", 28);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("A相频率", "Number", 55, 0, 1, 0, "byte", false, "", true, "JST_A_RATE", 29);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("B相频率", "Number", 56, 0, 1, 0, "byte", false, "", true, "JST_B_RATE", 30);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("C相频率", "Number", 57, 0, 1, 0, "byte", false, "", true, "JST_C_RATE", 31);

            //drf.JSTT_RuleDataItems.AddDataRuleItem("A相有功电量", "Number", 58, 0, 6, 0, "byte", false, "", true, "JST_A_ACT_ENERGY", 32);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("B相有功电量", "Number", 64, 0, 6, 0, "byte", false, "", true, "JST_B_ACT_ENERGY", 33);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("C相有功电量", "Number", 70, 0, 6, 0, "byte", false, "", true, "JST_C_ACT_ENERGY", 34);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("A相无功电量", "Number", 76, 0, 6, 0, "byte", false, "", true, "JST_A_REACT_ENERGY", 35);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("B相无功电量", "Number", 82, 0, 6, 0, "byte", false, "", true, "JST_B_REACT_ENERGY", 36);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("C相无功电量", "Number", 88, 0, 6, 0, "byte", false, "", true, "JST_C_REACT_ENERGY", 37);


            //drf.JSTT_RuleDataItems.AddDataRuleItem("和校验", "Number", 1021, 0, 2, 0, "byte", false, "", false, "",38);
            //drf.JSTT_RuleDataItems.AddDataRuleItem("结束符", "Number", 1023, 0, 1, 0, "byte", true, "16H", false, "", 39);

            JSTT_DataRuleSerializer<JSTT_DataRuleFormats>.WriteFile("JSTT_RULE_01.xml", drf);


            //JSTT_DataRuleMatchs drm = new JSTT_DataRuleMatchs();
            //drm.AddDataMatch(new DataMatchItem("起始位1","68H","Number",0,1));
            //drm.AddDataMatch(new DataMatchItem("起始位2","68H","Number",7,1));
            //drm.AddDataMatch(new DataMatchItem("设备类型", "1", "Number", 11, 1));
            //drm.AddDataMatch(new DataMatchItem("结束符", "16H", "Number", 1023, 1));

            //JSTT_DataRuleSerializer<JSTT_DataRuleMatchs>.WriteFile("JSTT_RULE_MATCH_01.xml", drm);

        }
    }
}
